<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" >
</head>
<body>

<?php 

require 'facebook-php-sdk/src/facebook.php';

// create application instance
$facebook = new Facebook(array(
'appId' => '107856579288360',
'secret' => '1111111111111111111111',
'cookie' => true,
));

$session = $facebook->getSession();

if (!empty($session))
{
    try{
        $uid = $facebook->getUser();
        $user = $facebook->api('/me');
		$fwends = $facebook->api('me/friends');
    }catch (Exception $e){}

    if (!empty($user))
    {   
        //if($_GET['installed'] == '1')
        //{
            //header("Location: http://apps.facebook.com/markomeara_firstapp");
        //}
       // header("Location: http://apps.facebook.com/markomeara_firstapp/");
        echo "Hello, ".$user['first_name'];
		$length = sizeof($fwends[data]);
		echo $length."<br />";
   //     echo "Session: ".$user;
		for($i = 0; $i < $length; $i++){
			print($fwends[data][$i]['name']." ".$fwends[data][$i]['id']."<br />");
		}
		//print_r($fwends);
    }
    else{
        die("Error occurred");
		echo "Exception:... ".$e;
	}

}
else{
    
	
	$url = $facebook->getLoginUrl();
	//GOTO($url);
	echo "<a href ='" . $url . "'>Click</a>";
}
?>
</body>
</html>

